<template>
  <div class="exhibit-process">
    <div class="page-header">
      <div class="container">
        <h1 class="page-title">{{ '参展流程' }}</h1>
        <p class="page-subtitle">{{ pageData.subtitle || '了解参展的详细流程和步骤' }}</p>
      </div>
    </div>
    <div class="container">
      <section class="process-section">
        <h2 class="section-title">{{ pageData.title || '参展流程' }}</h2>
        <div class="process-steps">
          <div class="step-item" v-for="(step, index) in exhibitProcess" :key="step.id">
            <div class="step-number">{{ index + 1 }}</div>
            <div class="step-content">
              <h3>{{ step.title }}</h3>
              <p>{{ step.description }}</p>
            </div>
          </div>
        </div>
      </section>
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from 'vue'
import { subpageApi } from '@/api/user'

export default {
  name: 'ExhibitProcess',
  setup() {
    const pageData = ref({})
    const exhibitProcess = ref([])
    
    // 默认参展流程数据 - 仅作为API失败时的fallback
    const defaultExhibitProcess = []

    const loadPageData = async () => {
      try {
        const response = await subpageApi.getSubpageByKey('exhibitors', 'exhibit-process')
        if (response && response.code === '200' && response.data) {
          pageData.value = response.data
          
          // 解析参展流程数据
          if (response.data.content) {
            try {
              // 尝试解析JSON内容
              if (response.data.content.trim().startsWith('[') || response.data.content.trim().startsWith('{')) {
                const contentData = JSON.parse(response.data.content)
                if (Array.isArray(contentData.steps)) {
                  exhibitProcess.value = contentData.steps
                } else if (Array.isArray(contentData)) {
                  exhibitProcess.value = contentData
                } else {
                  exhibitProcess.value = []
                }
              } else {
                // 如果是纯文本内容，转换为结构化数据
                const textContent = response.data.content
                exhibitProcess.value = [
                  {
                    id: 1,
                    title: '在线报名',
                    description: textContent.includes('报名') ? textContent : '填写参展申请表，提交企业基本信息'
                  },
                  {
                    id: 2,
                    title: '审核确认',
                    description: textContent.includes('审核') ? textContent : '组委会审核申请材料，确认展位分配'
                  },
                  {
                    id: 3,
                    title: '签订合同',
                    description: textContent.includes('合同') ? textContent : '确认展位后签订参展合同，支付展位费用'
                  },
                  {
                    id: 4,
                    title: '展位确认',
                    description: textContent.includes('展位') ? textContent : '完成付款后确认展位，安排展位搭建'
                  }
                ]
                console.log('参展流程数据已转换为结构化格式')
              }
            } catch (e) {
              console.error('解析参展流程数据失败:', e)
              // 使用默认数据
              exhibitProcess.value = getDefaultExhibitProcess()
            }
          } else {
            // 使用默认数据
            exhibitProcess.value = getDefaultExhibitProcess()
          }
        } else {
          // 使用默认数据
          exhibitProcess.value = getDefaultExhibitProcess()
        }
      } catch (error) {
        console.error('加载参展流程数据失败:', error)
        // 使用默认数据
        exhibitProcess.value = getDefaultExhibitProcess()
      }
    }

    // 获取默认的参展流程数据
    const getDefaultExhibitProcess = () => {
      return [
        {
          id: 1,
          title: '在线报名',
          description: '填写参展申请表，提交企业基本信息'
        },
        {
          id: 2,
          title: '审核确认',
          description: '组委会审核申请材料，确认展位分配'
        },
        {
          id: 3,
          title: '签订合同',
          description: '确认展位后签订参展合同，支付展位费用'
        },
        {
          id: 4,
          title: '展位确认',
          description: '完成付款后确认展位，安排展位搭建'
        }
      ]
    }

    onMounted(() => {
      loadPageData()
    })

    return {
      pageData,
      exhibitProcess
    }
  }
}
</script>

<style scoped>
.exhibit-process {
  min-height: 100vh;
  background: linear-gradient(135deg, #320063 0%, #4a0a8a 100%);
}

.page-header {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  padding: 120px 0 80px 0;
  margin-top: 0;
  text-align: center;
  color: white;
}

.page-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.page-subtitle {
  font-size: 1.2rem;
  opacity: 0.9;
  margin-bottom: 0;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.process-section {
  background: white;
  border-radius: 20px;
  padding: 3rem;
  margin: 2rem 0;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 2rem;
  color: #333;
  margin-bottom: 2rem;
  text-align: center;
}

.process-steps {
  max-width: 800px;
  margin: 0 auto;
}

.step-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, #f8f9ff 0%, #e8f0ff 100%);
  border-radius: 15px;
  border: 1px solid #e0e7ff;
  transition: transform 0.3s ease;
}

.step-item:hover {
  transform: translateX(10px);
}

.step-number {
  flex-shrink: 0;
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #320063 0%, #667eea 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.5rem;
  font-weight: 700;
  margin-right: 1.5rem;
}

.step-content h3 {
  font-size: 1.3rem;
  color: #320063;
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.step-content p {
  color: #666;
  line-height: 1.6;
  font-size: 1rem;
  margin: 0;
}

@media (max-width: 768px) {
  .process-section {
    padding: 2rem;
    margin: 1rem 0;
  }
  
  .section-title {
    font-size: 1.5rem;
  }
  
  .step-item {
    flex-direction: column;
    text-align: center;
  }
  
  .step-number {
    margin-right: 0;
    margin-bottom: 1rem;
  }
  
  .page-title {
    font-size: 2rem;
  }
  
  .page-subtitle {
    font-size: 1rem;
  }
}
</style>